
// 外部js文件引入，渲染试卷
testPaper(questionList)
addTestPaper(questionList)


/* 
删除题目
*/
function deleteQuestion(e) {
  const btnDelete = e.target.dataset.id
  console.log(btnDelete)
  questionList.splice(btnDelete, 1)
  localStorage.setItem('questionList', JSON.stringify(questionList))


  // 更新题库id
  questionList.forEach((question, index) => {
    question.id = index + 1
  })
  localStorage.setItem('questionList', JSON.stringify(questionList))

  // 重新渲染试卷
  testPaper(questionList)
  addTestPaper(questionList)
}


/* 
搜索试题
*/
function search() {
  // 1. 获取搜索关键词
  let key = document.querySelector('#key').value
  // 2. 过滤: 将试题中包含key内容保留下来 filter()
  let result = questionList.filter(item => {
    return item.question.includes(key)
  })
  testPaper(result)
  addTestPaper(result)
}